package io.renren.modules.sys.customer.controller;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.Arrays;
import java.util.Map;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import io.renren.common.validator.ValidatorUtils;
import io.renren.modules.sys.customer.entity.BtCustomerProDetailEntity;
import io.renren.modules.sys.customer.service.BtCustomerProDetailService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 商品详情
 *
 * @author goudandan
 * @email resjz1@163.com
 * @date 2018-09-19 17:01:33
 */
@RestController
@RequestMapping("sys/btcustomerprodetail")
public class BtCustomerProDetailController {
    @Autowired
    private BtCustomerProDetailService btCustomerProDetailService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("sys:btcustomerprodetail:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = btCustomerProDetailService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{proid}")
   // @RequiresPermissions("sys:btcustomerprodetail:info")
    public R info(@PathVariable("proid") Long proid){
        BtCustomerProDetailEntity btCustomerProDetail = btCustomerProDetailService.selectOne(new EntityWrapper<BtCustomerProDetailEntity>().eq("pro_id",proid));

        return R.ok().put("btCustomerProDetail", btCustomerProDetail);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("sys:btcustomerprodetail:save")
    public R save(@RequestBody BtCustomerProDetailEntity btCustomerProDetail){
        String ec="";
        try {
            ec = URLDecoder.decode(btCustomerProDetail.getContext(),"utf-8") ;
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        btCustomerProDetail.setContext(ec);

        Long pkey =btCustomerProDetailService.insertOneBackprimkey(btCustomerProDetail);

        return R.ok().put("pkey",pkey);
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
   // @RequiresPermissions("sys:btcustomerprodetail:update")
    public R update(@RequestBody BtCustomerProDetailEntity btCustomerProDetail){
        ValidatorUtils.validateEntity(btCustomerProDetail);
        String ec="";
        try {
            ec = URLDecoder.decode(btCustomerProDetail.getContext(),"utf-8") ;
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        btCustomerProDetail.setContext(ec);
        btCustomerProDetailService.updateAllColumnById(btCustomerProDetail);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("sys:btcustomerprodetail:delete")
    public R delete(@RequestBody Long[] ids){
        btCustomerProDetailService.deleteBatchIds(Arrays.asList(ids));

        return R.ok();
    }

}
